package com.gxa.ehome.proxy;

import com.gxa.ehome.service.SysUserService;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Arrays;
@Component("methodInterceptor")
public class SysUserServiceMethodInterceptor implements MethodInterceptor {

    //需要实现拦截方法
    private SysUserService sysUserService = null;

    public SysUserServiceMethodInterceptor(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("执行方法:" + method.getName() + ",传递的参数是" + Arrays.toString(objects));
        Object invoke = method.invoke(sysUserService, objects);
        //操作后的记录:
        System.out.println("方法成功执行,返回结果是:" + invoke);
        return invoke;
    }
}
